package jok.thread;

public class FruitBuyer implements Runnable {

	private Fruit fruit;

	public FruitBuyer(Fruit fruit) {
		super();
		this.fruit = fruit;
	}

	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			synchronized (fruit) {
				if (!fruit.isExist()) {
					try {
						fruit.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				System.out.println(fruit.getName() + "被买走了");
				fruit.setExist(false);
				fruit.notify();
			}
		}
	}

}
